package pattern.structrual.event;

import java.lang.reflect.Array;
import java.util.ArrayList;

/**
 * 事件源：事件发生的地方
 * @Author Gavin
 * @date 2021.03.05 15:12
 */
public class EventSource {
    public final static ArrayList<EventListener<Event>> listenerList = new ArrayList<>();

    public void addListener(EventListener<Event> eventListener) {
        listenerList.add(eventListener);
    }

    public void notifyEvent(Event event) {
        for (EventListener<Event> eventListener : listenerList) {
            eventListener.handleEvent(event);
        }
    }
}
